import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsNumber } from 'class-validator';

// VIP套餐枚举
export enum VipPackageType {
  MONTHLY = 1,
  QUARTERLY = 2,
  YEARLY = 3,
}

// 支付方式枚举
export enum PaymentMethod {
  APPLE = 'APPLE',
  MOMO = 'MOMO',
}

// 创建VIP订单DTO
export class CreateVipOrderDto {
  @ApiProperty({
    description: 'VIP套餐ID',
    example: 1,
    enum: VipPackageType,
  })
  @IsNumber()
  @IsNotEmpty()
  packageId: number;

  @ApiProperty({
    description: '支付方式',
    example: 'MOMO',
    enum: PaymentMethod,
  })
  @IsEnum(PaymentMethod)
  @IsNotEmpty()
  paymentMethod: PaymentMethod;
}

// VIP订单响应DTO
export class VipOrderResponseDto {
  @ApiProperty({ description: '订单ID' })
  orderId: string;

  @ApiProperty({ description: '订单编号' })
  orderNo: string;

  @ApiProperty({ description: '订单标题' })
  title: string;

  @ApiProperty({ description: '订单金额' })
  amount: number;

  @ApiProperty({ description: '订单状态' })
  status: string;

  @ApiProperty({ description: '支付方式' })
  paymentMethod: string;

  @ApiProperty({ description: '套餐名称' })
  packageName: string;

  @ApiProperty({ description: '套餐时长（天）' })
  duration: number;

  @ApiProperty({ description: 'VIP到期时间' })
  vipExpiredAt: string;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;
}

// VIP信息响应DTO
export class VipInfoResponseDto {
  @ApiProperty({ description: '用户ID' })
  userId: number;

  @ApiProperty({ description: '用户昵称' })
  nickname: string;

  @ApiProperty({ description: '是否为VIP' })
  isVip: boolean;

  @ApiProperty({ description: 'VIP到期时间', required: false })
  vipExpiredAt: string | null;

  @ApiProperty({ description: '剩余天数' })
  remainingDays: number;

  @ApiProperty({ description: '积分' })
  points: number;
}

// VIP套餐DTO
export class VipPackageDto {
  @ApiProperty({ description: '套餐ID' })
  id: number;

  @ApiProperty({ description: '套餐名称' })
  name: string;

  @ApiProperty({ description: '套餐时长（天）' })
  duration: number;

  @ApiProperty({ description: '套餐价格' })
  price: number;

  @ApiProperty({ description: '套餐描述' })
  description: string;
}

// Swagger API响应包装器
export class ApiVipOrderResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: VipOrderResponseDto })
  data: VipOrderResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

export class ApiVipInfoResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: VipInfoResponseDto })
  data: VipInfoResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

// 积分套餐DTO
export class PointsPackageDto {
  @ApiProperty({ description: '套餐ID' })
  id: number;

  @ApiProperty({ description: '套餐名称' })
  name: string;

  @ApiProperty({ description: '积分数量' })
  points: number;

  @ApiProperty({ description: '套餐价格' })
  price: number;

  @ApiProperty({ description: '套餐描述' })
  description: string;

  @ApiProperty({ description: '是否推荐' })
  isRecommended: boolean;

  @ApiProperty({ description: '折扣金额' })
  discount: number;

  @ApiProperty({ description: '实际价格（原价-折扣）' })
  get actualPrice(): number {
    return this.price - this.discount;
  }

  @ApiProperty({ description: '性价比（积分/元）' })
  get valueRatio(): number {
    return Math.round(this.points / this.actualPrice);
  }
}

// 创建积分订单DTO
export class CreatePointsOrderDto {
  @ApiProperty({
    description: '积分套餐ID',
    example: 1,
  })
  @IsNumber()
  @IsNotEmpty()
  packageId: number;

  @ApiProperty({
    description: '支付方式',
    example: 'MOMO',
    enum: PaymentMethod,
  })
  @IsEnum(PaymentMethod)
  @IsNotEmpty()
  paymentMethod: PaymentMethod;
}

// 积分订单响应DTO
export class PointsOrderResponseDto {
  @ApiProperty({ description: '订单ID' })
  orderId: string;

  @ApiProperty({ description: '订单编号' })
  orderNo: string;

  @ApiProperty({ description: '订单标题' })
  title: string;

  @ApiProperty({ description: '订单金额' })
  amount: number;

  @ApiProperty({ description: '订单状态' })
  status: string;

  @ApiProperty({ description: '支付方式' })
  paymentMethod: string;

  @ApiProperty({ description: '套餐名称' })
  packageName: string;

  @ApiProperty({ description: '积分数量' })
  points: number;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;
}

// Swagger API响应包装器
export class ApiPointsOrderResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: PointsOrderResponseDto })
  data: PointsOrderResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

// 积分余额响应DTO
export class PointsBalanceResponseDto {
  @ApiProperty({ description: '当前积分余额' })
  points: number;
}

// Swagger API响应包装器
export class ApiPointsBalanceResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: PointsBalanceResponseDto })
  data: PointsBalanceResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

// 签到响应DTO
export class SignInResponseDto {
  @ApiProperty({ description: '签到ID' })
  id: number;

  @ApiProperty({ description: '用户ID' })
  userId: number;

  @ApiProperty({ description: '签到日期' })
  signInDate: string;

  @ApiProperty({ description: '本次签到获得的积分' })
  points: number;

  @ApiProperty({ description: '连续签到天数' })
  continuous: number;

  @ApiProperty({ description: '签到消息' })
  message: string;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;
}

// 签到记录DTO
export class SignInRecordDto {
  @ApiProperty({ description: '签到ID' })
  id: number;

  @ApiProperty({ description: '签到日期' })
  signInDate: string;

  @ApiProperty({ description: '本次签到获得的积分' })
  points: number;

  @ApiProperty({ description: '连续签到天数' })
  continuous: number;

  @ApiProperty({ description: '积分获得原因' })
  reason: string;

  @ApiProperty({ description: '创建时间' })
  createdAt: string;
}

// 签到状态DTO
export class SignInStatusResponseDto {
  @ApiProperty({ description: '用户ID' })
  userId: number;

  @ApiProperty({ description: '今日是否已签到' })
  todaySignedIn: boolean;

  @ApiProperty({ description: '连续签到天数' })
  continuousDays: number;

  @ApiProperty({ description: '本月签到天数' })
  monthSignInDays: number;

  @ApiProperty({ description: '今日签到时间' })
  todaySignInTime: string | null;

  @ApiProperty({ description: '下次签到时间' })
  nextSignInTime: string;

  @ApiProperty({ description: '签到提醒' })
  message: string;
}

// Swagger API响应包装器
export class ApiSignInResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: SignInResponseDto })
  data: SignInResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

export class ApiSignInListResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: [SignInRecordDto] })
  data: SignInRecordDto[];

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}

export class ApiSignInStatusResponseDto {
  @ApiProperty({ description: '响应码' })
  code: number;

  @ApiProperty({ description: '响应消息' })
  message: string;

  @ApiProperty({ description: '响应数据', type: SignInStatusResponseDto })
  data: SignInStatusResponseDto;

  @ApiProperty({ description: '时间戳' })
  timestamp: number;

  @ApiProperty({ description: '请求ID' })
  requestId: string;
}
